var View = (function() {
  return Class.create({
    constructor: function(properties) {
      properties = properties || {};
    },

    //返回舞台
    getStage: function() {
      var obj = this,
        parent;
      while ((parent = obj.parent)) {
        obj = parent;
      } //寻找最老的爸爸
      if (obj.canvas) {
        return obj;
      }
      return canvas;
    },

    getScaledWidth: function() {
      return this.width * this.scaleX;
    },

    getScaledHeight: function() {
      return this.height * this.scaleY;
    },

    addTo: function(container, index) {
      if (typeof index == "number") container.addChildAt(this, index);
      else container.addChild(this);
      return this;
    },

    removeFrom: function() {
      var parent = this.parent;
      if (parent) parent.removeChild(this);
      return this;
    },

    //取得每一个对象的边框
    getBounds:function(){
      var w=this.width,h=this.height,
      mtx=this.getConcatenatedMatrix(),
      poly=this.boundArea||[
        {x:0,y:0},{x:w,y:0},{x:w,y:h},{x:0,y:h}
      ],
      vetrex=[],point,x,y,minX,maxX,minY,maxY;

      for(var i=0,len=poly.length;i<len;i++){
        point=mtx.transformPoint(poly[i],true,true);
        x=point.x;
        y=point.y;
        if(i==0){
          minX=maxX=x;
          minY=maxY=y;
        }else{
          if(minX>x) minX=x;
          if(maxX<x) maxX=x;
          if(minY>y) minY=y;
          if(maxY<y) maxY=y;
        }
        vetrex=[i]=point;
      }
      vetrex.x=minX;
      vetrex.y=minY;
      vetrex.width=maxX-minX;
      vetrex.height=maxY-minY;
    },

    hitPoint: function(x, y) {
      var bound = this.getBounds();
      var isHit = false;
      if (
        x > bound.x &&
        x < bound.x + bound.width &&
        y > bound.y &&
        y < bound.y + bound.height
      ) {
        isHit = true;
      }
      return isHit;
    }
  });
})();

//view
//在游戏中所有的对象都是一个view
//包括舞台--容器---对象
//而舞台则是游戏中所有对象的祖先
